//
//  HeaderOfClickLvXingDi.m
//  SeeTheWorld
//
//  Created by dllo on 16/3/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HeaderOfClickLvXingDi.h"
#import "ModelOfClickLvXingDiHeader.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface HeaderOfClickLvXingDi ()

@property (nonatomic, retain)UIImageView *imageOfBack;
@property (nonatomic, retain)UILabel *labelOfNameC;
@property (nonatomic, retain)UILabel *labelOfNameE;
@property (nonatomic, retain)UILabel *labelOfDesc;

@end

@implementation HeaderOfClickLvXingDi

- (void)dealloc {
    [_labelOfDesc release];
    [_imageOfBack release];
    [_labelOfNameC release];
    [_labelOfNameE release];
    [super dealloc];
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        self.contentView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

        self.imageOfBack = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageOfBack];
        [_imageOfBack release];
        
        self.labelOfNameC = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfNameC];
        [_labelOfNameC release];
        self.labelOfNameC.font = [UIFont systemFontOfSize:20];
        self.labelOfNameC.textColor = [UIColor whiteColor];
        
        self.labelOfNameE = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfNameE];
        [_labelOfNameE release];
        self.labelOfNameE.font = [UIFont systemFontOfSize:18];
        self.labelOfNameE.textColor = [UIColor whiteColor];
        
        self.labelOfDesc = [[UILabel alloc] init];
        [self.contentView addSubview:self.labelOfDesc];
        [_labelOfDesc release];
        self.labelOfDesc.numberOfLines = 0;
        self.labelOfDesc.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);
        self.labelOfDesc.font = [UIFont systemFontOfSize:20];
      
    }
    
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageOfBack.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 320);
    self.labelOfNameC.frame = CGRectMake(20, self.imageOfBack.frame.size.height - 70, self.contentView.frame.size.width - 40, 30);
    self.labelOfNameE.frame = CGRectMake(20, self.imageOfBack.frame.size.height - 45, self.contentView.frame.size.width - 40, 30);
    self.labelOfDesc.frame = CGRectMake(10, 320 + 5, scWIDTH - 20, [self.class heightForLabel:self.labelOfDesc.text]);
   
}

- (void)passModel:(ModelOfClickLvXingDiHeader *)model {
    
    if ([model.image_url isKindOfClass:[NSNull class]] || [model.descrip isEqual:NULL]) {

        self.imageOfBack.image = [UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"];
        
    } else {
        
        [self.imageOfBack sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    }
    
    if ([model.name_zh_cn isKindOfClass:[NSNull class]] || [model.descrip isEqual:NULL]) {

        self.labelOfNameC.text = @"";
    } else {
        
        self.labelOfNameC.text = model.name_zh_cn;
    }
    
    if ([model.name_en isKindOfClass:[NSNull class]] || [model.descrip isEqual:NULL] || [model.descrip isEqual:@""]) {
        
      //  self.labelOfNameE.text = @"";
       
        
    } else {
        
        self.labelOfNameE.text = model.name_en;
    }
 
    
    if ([model.descrip isKindOfClass:[NSNull class]] || [model.descrip isEqual:NULL]) {
            
        self.labelOfDesc.text = @"";
            
    } else {
            
        self.labelOfDesc.text = model.descrip;
    }

}

/** 自适应高度 */
+ (CGFloat)heightForLabel:(NSString *)text {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(WIDTH - 20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]} context:nil];
    
    return rect.size.height;
}


+ (CGFloat)heightForCell:(ModelOfClickLvXingDiHeader *)model {
    
    if ([model.descrip isKindOfClass:[NSNull class]] || [model.descrip isEqualToString:@"(null)"]) {
        return 320;

    } else {
        
        CGFloat height = [HeaderOfClickLvXingDi heightForLabel:model.descrip];
        
        return height + 320 + 5;
    }
    
}





@end
